package com.lws.framework.listener;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

import com.lws.framework.cache.CacheService;

@Component
public class ApplicationContextListener implements ApplicationListener<ContextRefreshedEvent> {

    @Autowired
    private CacheService cacheService;

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        //防止重复执行。
        if (event.getApplicationContext().getParent() == null) {
            cacheService.init();
        }
    }

}
